package com.cjm.mhl.service;

import com.cjm.mhl.dao.DiningTableDAO;
import com.cjm.mhl.domain.DiningTable;

import java.util.List;

public class DiningTableService {
    private DiningTableDAO diningTabledao=new DiningTableDAO();
    //返回所有餐桌状态
    public List<DiningTable> list() {
        return diningTabledao.queryMulti("select id,state from diningTable",DiningTable.class);
    }
    //根据餐桌id查询对应餐桌的状态
    public DiningTable getDiningTable(int id) {
        return diningTabledao.querySingle("select * from diningtable where id= ?",DiningTable.class,id);
    }

    //成功预定餐桌，修改餐桌状态
    public boolean orderDiningTable(int id,String orderName,String orderTel) {
        int update = diningTabledao.update("update diningtable set state='已经预定' ,orderName=?,orderTel=? where id=?", orderName, orderTel,id);
        return update >0;
    }

//    修改餐桌状态
    public boolean updateDiningTableState(int id,String state) {
        int update = diningTabledao.update("update diningtable set state=? where id=?", state, id);
        return update >0;
    }
    // 提供方法，将餐桌设置空闲状态
    public boolean updateDiningTableFree(int id,String state){
        int update = diningTabledao.update("update diningtable set state='空' ,orderName=' ',orderTel=' ' where id= ?", id);
        return update >0;
    }
}
